﻿<link href="/SiteUI/MyBiz/MyNavi.css" rel="stylesheet" />

<div class="col-lg-10 col-lg-offset-1" id="slcSettingTarget">
    <a href="#" class="active" for="naviSetting">快速导航设置</a><span>&nbsp;|&nbsp;</span><a href="#" for="widgetSetting">桌面部件设置</a>
</div>

<div class="col-lg-10 col-lg-offset-1" id="pnlNaviSetting">
    <h3>选择要显示在页面头部的快速导航项</h3>
</div>

<div class="col-lg-10 col-lg-offset-1" id="pnlWidgetSetting">
    <div class="row">

    </div>
</div>


<div id="tplNaviItem" style="display:none">
    <div class="InfoBlock">
        <div class="ib_head row">
            <span class="ib_head_title">子系统标题</span>
        </div>
        <div class="row">
            <div class="ib_naviItem col-lg-3">
                <h4>应用标题</h4>
                <p>应用说明</p>
                <span class="ni_flag"><i></i>启用状态</span>
            </div>
        </div>
    </div>
    <div class="WidgetBlock col-lg-4">
        <div class="widgetItem">
            <h4>标题</h4>
            <p>描述</p>
            <span class="ni_flag"><i></i>已启用：未启用</span>
        </div>
    </div>
</div>
<script>
    pvMyNavi = {
        onUserReady: function () {
            pvMyNavi.makeNaviItem();
            pvMyNavi.makeWidget();
        },
        makeNaviItem: function () {
            //动态生成数据
            var html = "";
            for (var i = 0; i < User.setting.SubSystems.length; i++) {
                html += "<div class='InfoBlock'>";
                html += "<div class='ib_head row'>";
                html += "<span class='ib_head_title'>" + User.setting.SubSystems[i].Title + "</span>";
                html += "</div>";
                html += "<div class='row'>";
                html += "</div>";
                html += "</div>";
                var g = $(html);

                for (var j=0;j< User.setting.SubSystems[i].Items.length; j++) {
                    var itm = "";
                    if (User.setting.SubSystems[i].Items[j].Active) {
                        itm += "<div class='ib_naviItem col-lg-3' >";
                        itm += "<span>" + User.setting.SubSystems[i].Items[j].Title + "</span><div class='switch_outboard switch_green' subsystem=" + i + " item=" + j + " ><div class='switch_inside switch_right' ></div></div>";
                        itm += "<p><b>tab:</b>" + User.setting.SubSystems[i].Items[j].Remark + "</p>";
                    }
                    else {
                        itm += "<div class='ib_naviItem col-lg-3' >";
                        itm += "<span>" + User.setting.SubSystems[i].Items[j].Title + "</span><div class='switch_outboard switch_gray' subsystem=" + i + " item=" + j + " ><div class='switch_inside ' ></div></div>";
                        itm += "<p><b>tab:</b>" + User.setting.SubSystems[i].Items[j].Remark + "</p>";

                    }
                    itm += "</div>";
                    var gi = $(itm);
                    gi.appendTo(g.children(".row").eq(1));
                }
                $("#pnlNaviSetting").append(g);
                html = "";
            }
        },
        makeWidget: function () {
            for (var i = 0; i < User.setting.Widgets.length; i++) {
                var w = User.setting.Widgets[i];
                var wgBlock = $("<div class='WidgetBlock col-lg-4'>");
                if (w.Active == true) {
                    var wgItem = $("<div class='widgetItem'>").appendTo(wgBlock);
                    wgItem.append("<span>" + w.Title + "</span><div class='switch_outboard switch_green' wgitem=" + i + " ><div class='switch_inside switch_right ' ></div></div>");
                    wgItem.append("<p><b>tab:</b>" + w.Remark + "</p>");
                    
                }
                else {
                    var wgItem = $("<div class='widgetItem'>").appendTo(wgBlock);
                    wgItem.append("<span>" + w.Title + "</span><div class='switch_outboard switch_gray' wgitem=" + i + "  ><div class='switch_inside ' ></div></div>");
                    wgItem.append("<p><b>tab</b>" + w.Remark + "</p>");
                }
                wgBlock.appendTo("#pnlWidgetSetting>.row");
            }
        },
        onNaviItemClick: function (ev) {           
            var s=$(this).attr("subsystem");
            var i = $(this).attr("item");
        
            if (User.setting.SubSystems[s].Items[i].Active == true) {
                User.setting.SubSystems[s].Items[i].Active = false;
                $(ev.currentTarget).children(".switch_inside").animate({ marginLeft: "0" }, 300);
                $(ev.currentTarget).removeClass("switch_green");
                $(ev.currentTarget).addClass("switch_gray");
            }
            else {
                User.setting.SubSystems[s].Items[i].Active = true;
                $(ev.currentTarget).children(".switch_inside").animate({ marginLeft: "2rem" }, 300);
                $(ev.currentTarget).removeClass("switch_gray");
                $(ev.currentTarget).addClass("switch_green");
            }
            var sv = JSON.parse(JSON.stringify(User.setting));
            sv.SubSystems.forEach(function (sub) {
                sub.Items = sub.Items.filter("Active", true);
            });
            sv.Widgets = sv.Widgets.filter("Active", true);
            $.post("/MyBiz/UpdateAcntSetting", { setting: JSON.stringify(sv) });
        },
        onWidgetItemClick: function (ev) {
            
            var wi = $(this).attr("wgitem");
                
            if (User.setting.Widgets[wi].Active == true) {
                User.setting.Widgets[wi].Active = false;
                $(ev.currentTarget).children(".switch_inside").animate({ marginLeft: "0" }, 300);
                $(ev.currentTarget).removeClass("switch_green");
                $(ev.currentTarget).addClass("switch_gray");
            }
            else {
                User.setting.Widgets[wi].Active = true;
                $(ev.currentTarget).children(".switch_inside").animate({ marginLeft: "2rem" }, 300);
                $(ev.currentTarget).removeClass("switch_gray");
                $(ev.currentTarget).addClass("switch_green");
            }
            var sv = JSON.parse(JSON.stringify(User.setting));
            sv.SubSystems.forEach(function (sub) {
                sub.Items = sub.Items.filter("Active", true);
            });
            sv.Widgets = sv.Widgets.filter("Active", true);
            $.post("/MyBiz/UpdateAcntSetting", { setting: JSON.stringify(sv) });
        },
        onSettingShift: function (ev) {
            $("#slcSettingTarget>a").removeClass("active");
            var a= $(ev.currentTarget).addClass("active");
            if(a.attr("for")=="naviSetting")
            {
                $("#pnlWidgetSetting").hide();
                $("#pnlNaviSetting").fadeIn();
            }
            else {
                $("#pnlNaviSetting").hide();
                $("#pnlWidgetSetting").fadeIn();
            }
        }
    }
    SoBiz.Ready(function () {
        $("#pnlNaviSetting").delegate(".switch_outboard", "click", null, pvMyNavi.onNaviItemClick);
        $("#pnlWidgetSetting").delegate(".switch_outboard", "click", null, pvMyNavi.onWidgetItemClick);

        $("#slcSettingTarget").delegate("a", "click", pvMyNavi.onSettingShift);

        var to = getUrlParam("go");
        if (to == 'widget') {
            $("#slcSettingTarget [for='widgetSetting']").click();
        }

        SoBiz.Login(pvMyNavi.onUserReady);
    })
</script>
